package com.example.demo.mapper;

import com.example.demo.entity.Chapter;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface ChapterMapper {
    /**
     * 增加章节
     * */
    @Insert("insert into chapter values(default,#{chapter_name},#{chapter_type},#{chapter_node})")
    public int insertchapter(String chapter_name,Integer chapter_type,Integer chapter_node);
    /**
     * 章节查询
     * */
    @Select("select * from chapter")
    public List<Chapter> selchapter();
    @Select("select * from chapter where chapter_id=#{chapter_id}")
    public Chapter selone(Integer chapter_id);
    @Select("select * from chapter where chapter_node=#{chapter_node}")
    public List<Chapter> selnode(Integer chapter_node);
    /**
     * 单章节所属章节查询
     * */
    @Select("SELECT chapter_name FROM chapter WHERE chapter_id=(SELECT chapter_node FROM chapter WHERE chapter_id=#{chapter_id})")
    public Chapter selonecha(Integer chapter_id);
    @Select("select chapter_node from chapter where chapter_id=#{chapter_id}")
    public Chapter selnodes(Integer chapter_id);
    /**
     * 章节名查询
     * */
    @Select("SELECT * FROM chapter WHERE chapter_id=#{chapter_id}")
    public Chapter selcnm(Integer chapter_id);
    /**
     * 父级章节查询
     * */
    @Select("select * from chapter where chapter_node=0")
    public List<Chapter> selfath();
    /**
     * 更改章节
     * */
    @Update("update chapter set chapter_name=#{chapter_name},chapter_type=#{chapter_type} where chapter_id=#{chapter_id}")
    public int updtchapter(String chapter_name,Integer chapter_type,Integer chapter_id);
    /**
     * 删除章节(父级目录+子目录)
     * */
    @Delete("delete from chapter where chapter_id=#{chapter_id} or chapter_node=#{chapter_id}")
    public int delchapter(Integer chapter_id);
    /**
     * 删除子目录
     * */
    @Delete("delete from chapter where chapter_id=#{chapter_id}")
    public int delone(Integer chapter_id);
    /**
     * 更改章节状态
     * */
    @Update("update chapter set chapter_type=#{chapter_type} where chapter_id=#{chapter_id}")
    public int updtchatype(Integer chapter_type,Integer chapter_id);
}
